package ru.aslanov.schedule.client.ds;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceDateTimeField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import ru.aslanov.schedule.client.ScheduleUser;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * Created: Feb 3, 2010 12:46:47 PM
 *
 * @author Sergey Aslanov
 */
public class CalendarEventsDS extends ChildDS {
    private static Map<String, DataSource> instances = new HashMap<String, DataSource>();

    public static DataSource getInstance(ScheduleUser scheduleUser) {
        DataSource dataSource = instances.get(scheduleUser.getScheduleKey());
        if (dataSource == null) {
            dataSource = new CalendarEventsDS(scheduleUser.getScheduleKey(), scheduleUser);
            instances.put(scheduleUser.getScheduleKey(), dataSource);
        }
        return dataSource;
    }


    public CalendarEventsDS(String scheduleKey, InputLangProvider inputLangProvider) {
        super("CalendarEvents", scheduleKey, "schedule", inputLangProvider);

        DataSourceTextField eventIdField = new DataSourceTextField("eventId");
        eventIdField.setPrimaryKey(true);

        DataSourceTextField groupKeyField = new DataSourceTextField("groupKey");
        groupKeyField.setHidden(true);
        DataSourceTextField nameField = new DataSourceTextField("name");
        DataSourceTextField descField = new DataSourceTextField("description");
        DataSourceDateTimeField startDateField = new DataSourceDateTimeField("startDate");
        DataSourceDateTimeField endDateField = new DataSourceDateTimeField("endDate");

        DataSourceTextField locationKey = new DataSourceTextField("locationKey");
        locationKey.setHidden(true);

        DataSourceTextField teacherKey = new DataSourceTextField("teacherKey");
        teacherKey.setHidden(true);

        setFields(eventIdField, groupKeyField, nameField, descField, startDateField, endDateField, locationKey, teacherKey);
    }
}
